<?php
namespace app\home\controller;

use think\Controller;
use think\Session;
use think\Request;
use app\home\model\UserModel;

class User extends Common
{
	/**
	*	个人中心页面
	*/
	public function home()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getUser();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	个人信息
	*/
	public function getUser()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getUser();
		if($list){
			return returnJson($code=0,$msg="获取成功",$list);
		}else{
			return returnJson($code=1,$msg="获取成功",$list);
		}
	}

	/**
	*	个人信息
	*/
	public function person()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getUser();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	联系方式
	*/
	public function contact()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getUser();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	修改联系方式
	*/
	public function editcontact()
	{
		/* 获取手机号码 */
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->editphone($data);
		if($list){
			return returnJson($code=0,$msg="修改成功",$list);
		}else{
			return returnJson($code=1,$msg="修改失败",$list);
		}
	}

	/**
	*	会员名称
	*/
	public function username()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getUser();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	修改会员名称
	*/
	public function editusername()
	{

		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->editusername($data);
		if($list){
			return returnJson($code=0,$msg="修改成功",$list);
		}else{
			return returnJson($code=1,$msg="修改失败",$list);
		}
	}

	/**
	*	会员邀请ID
	*/
	public function user_recomid()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getUser();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	修改会员邀请ID
	*/
	public function edituserrecomid()
	{

		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->edituserrecomid($data);
		if($list){
			return returnJson($code=0,$msg="修改成功",$list);
		}else{
			return returnJson($code=1,$msg="修改失败",$list);
		}
	}

	/**
	*	店铺名称
	*/
	public function userstore()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getUser();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	修改店铺名称
	*/
	public function edituserstore()
	{

		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->edituserstore($data);
		if($list){
			return returnJson($code=0,$msg="修改成功",$list);
		}else{
			return returnJson($code=1,$msg="修改失败",$list);
		}
	}

	/**
	*	收货地址列表
	*/
	public function address()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getUserAddressIndex();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	添加收货地址
	*/
	public function addAddress()
	{
		return $this->fetch();
	}


	/**
	*	添加会员的收货地址提交
	*/
	public function addAddressPost()
	{
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->addUserAddress($data);
		if($list){
			return returnJson($code=0,$msg="添加成功",$list);
		}else{
			return returnJson($code=1,$msg="添加失败",$list);
		}
	}

	/**
	*	修改会员收货地址
	*/
	public function editAddress()
	{
		$data = $this->request->param();
		if($data){
			$UserModel = new UserModel();
			$list = $UserModel->editAddress($data['id']);
		}
		$this->assign('list',$list);
		return $this->fetch();
	}


	/**
	*	修改会员的收货地址提交
	*/
	public function editAddressPost()
	{
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->editAddressPost($data['id'],$data);
		if($list){
			return returnJson($code=0,$msg="修改成功",$list);
		}else{
			return returnJson($code=1,$msg="修改失败",$list);
		}
	}

	/**
	*	选择哪个为默认地址
	*/
	public function editDaddress()
	{
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->editDaddressPost($data['id']);
		if($list){
			return returnJson($code=0,$msg="修改成功",$list);
		}else{
			return returnJson($code=1,$msg="修改失败",$list);
		}
	}

	/**
	*	删除默认地址
	*/
	public function deleteAddress()
	{
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->deleteUserAddress($data['id']);
		if($list===2){
			return returnJson($code=0,$msg="删除成功",$list);
		}elseif($list===3){
			return returnJson($code=1,$msg="默认地址不能删除",$list);
		}elseif($list===4){
			return returnJson($code=2,$msg="删除失败",$list);
		}
	}

	/**
	*	官方活动
	*/
	public function events()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getevents();
		if($list){
			return returnJson($code=0,$msg="修改成功",$list);
		}else{
			return returnJson($code=1,$msg="修改失败",$list);
		}
	}

	/**
	*	我的订单页
	*/
	public function order()
	{
		return $this->fetch();
	}

	/**
	*	订单列表
	*/
	public function getUserOrder()
	{
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->getUserOrder($data['o_status']);
		
		if($list){
			return returnJson($code=0,$msg="获取成功",$list);
		}else{
			return returnJson($code=1,$msg="获取失败",$list);
		}
	}

	/**
	*	订单列表-商品信息
	*/
	public function getOrderGoods()
	{
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->getOrderGoods($data['gids']);
		if($list){
			return returnJson($code=0,$msg="获取成功",$list);
		}else{
			return returnJson($code=1,$msg="获取失败",$list);
		}
	}

	/**
	*	订单列表-商品规格信息
	*/
	public function getOrderGoodsInfo()
	{
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->getOrderGoodsInfo($data['gid'],$data['oid']);
		if($list){
			return returnJson($code=0,$msg="获取成功",$list);
		}else{
			return returnJson($code=1,$msg="获取失败",$list);
		}
	}

	/**
	*	我的支出
	*/
	public function spending()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getUserSpend();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	订单物流信息
	*/
	public function logistics()
	{
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->getOrderLog($data['id']);
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	申请列表
	*/
	public function apply()
	{
		return $this->fetch();
	}

	/**
	*	专柜列表
	*/
	public function applyIndex()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getApply();
		if($list){
			return returnJson($code=0,$msg='获取成功',$list);
		}else{
			return returnJson($code=1,$msg='获取失败',$list);
		}
	}

	/**
	*	合伙人列表
	*/
	public function partnerIndex()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getPartner();
		if($list){
			return returnJson($code=0,$msg='获取成功',$list);
		}else{
			return returnJson($code=1,$msg='获取失败',$list);
		}
	}

	/**
	*	商品佣金列表
	*/
	public function commission()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getCommission();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	我的收益
	*/
	public function earnings()
	{
		return $this->fetch();
	}

	/**
	*	我的伙伴
	*/
	public function partner()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getParner();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	我的伙伴-月度详情
	*/
	public function monthly()
	{
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->UserOrders();
		$user = $UserModel->getPartnerOne($data['id']);
		$this->assign('list',$list);
		$this->assign('user',$user);
		return $this->fetch();
	}

/****************************** 用户提现 *******************************************/
	public function withdrawal()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getUser();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/* 提交页面 */
	public function withdrawalpost()
	{
		return $this->fetch();
	}
	
	public function addWithDrawal()
	{
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->addWithDrawal($data);
		if($list){
			return returnJson($code=0,$msg='提交成功',$list);
		}else{
			return returnJson($code=1,$msg='提交失败',$list);
		}
	}

	public function withdrawalsuccess()
	{
		$data = $this->request->param();
		$UserModel = new UserModel();
		$list = $UserModel->getOneWithDrawal($data['id']);
		$this->assign('list',$list);
		return $this->fetch();
	}

/************************** 提现记录 ************************************/

	public function withdrawalindex()
	{
		$UserModel = new UserModel();
		$list = $UserModel->getWithDrawalIndex();
		$this->assign('list',$list);
		return $this->fetch();
	}
}